<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Department extends Model
{
    use HasFactory;

    protected $fillable = ['name', 'user_id'];
    public $appends = ['users_count'];

    public function getUsersCountAttribute()
    {
        return $this->users()->count();
    }

    public function users()
    {
        return $this->hasMany(User::class);
    }

//    部门管理员
    public function manager()
    {
        return $this->belongsToMany(User::class, 'department_admin');
    }
}
